import { randomInt } from "@/utils"
import { Player } from '@/types/game/player'
import { getRandomItem } from "@/utils/array";
export const randomGetCountryNames = (num: number, exclude: string[] = []) => {
    return countryNameList.filter(name => !exclude.includes(name)).sort(() => Math.random() - 0.5).slice(0, num)
}
export const randomGetCountryName = (exclude: string[] = []) => {
    return getRandomItem(countryNameList.filter(name => !exclude.includes(name)));
}
export const createPlayer = (name: string , seat: number | null = null, isAi = false): Player => {
    return {
        id: String(randomInt(1, 99999999)).padStart(8, '0'),
        name,
        seat,
        isAi,
        isHost: false,
        isOnline: true,
        tokens: {
            fate: { base: 1, tempChanged: 0 },
            development: { base: 1, tempChanged: 0 },
            resource: { base: 8 },
            mobilization: { base: 1, tempChanged: 0 },
            military: [
                { type: "attack", base: 1, tempChanged: 0, bonus: 0 },
                { type: "defense", base: 1, tempChanged: 0, bonus: 0 }
            ]
        },
        states: [],
        lordCards: [],
        fateCards: {
            good: { base: 5 },
            bad: { base: 5 }
        }
    }
}
export const sumMilitary = (player: Player, type: "attack" | "defense") => {
    const militaryTokenCount = { base: 0, extra: 0 };
    for (const token of player.tokens.military) {
        if (token.type === type) {
            militaryTokenCount.base += token.base;
            militaryTokenCount.extra += token.tempChanged;
            militaryTokenCount.extra += token.bonus;
        }
    }
    return militaryTokenCount;
};
const countryNameList = [
    '晋', '楚', '秦', '齐',
    '赵', '魏', '韩', '燕', '吴', '越',
    '鲁', '郑', '宋', '卫', '陈', '蔡', '曹',
    '蜀', '巴', '庸', '箕',
    '唐', '申', '邢', '杞', '虢', '虞', '随', '纪', '项',
    '许', '舒', '英', '邾', '莒', '郯', '谭', '贰', '郭',
    '戴', '息', '邓', '吕', '黄', '罗', '蓼', '薛', '徐',
    '滕', '散', '詹', '原', '樊', '雕', '召', '尹', '暴',
    '韦', '卞', '董', '养', '毫', '厉', '缯', '翟', '阴',
    '勾吴', '于越', '东虢', '北虢', '西虢', '南虢', '中山',
];
export default {
    createPlayer,
    sumMilitary,
    randomGetCountryName,
    randomGetCountryNames
}